Configure your project’s Info.plist file to ensure the necessary permissions for Bluetooth Low Energy (LE) and local network services are included. (Ensuring Privacy Compliance)
2
If enabling the Data Protection entitlement, allow access after your end users have unlocked their device for the first time after a system restart. (Setting Protection Entitlement)
Configure your app for compliance with Apple’s guidelines for iOS permissions by doing the following. For more information, see the official Apple documentation for Privacy.
1
From Xcode, add a new Custom iOS Target Properties entry:
From the left navigator area, click your project.
In the editor that appears, click Info tab.
Right-click any row in the list, and then select Add Row from the menu.
For instructions on configuring permissions for your app, see Cloud Authentication.
2
From your project’s Info.plistfile, add the following key-value pairs, which display as dismissable prompts to your end users explaining why the app requires certain permissions.
Copy
Ask AI
Key: NSBluetoothAlwaysUsageDescriptionType: StringValue: Uses Bluetooth to connect and sync with nearby devicesKey: NSBluetoothPeripheralUsageDescriptionType: StringValue: Uses Bluetooth to connect and sync with nearby devicesKey: NSLocalNetworkUsageDescriptionType: StringValue: Uses WiFi to connect and sync with nearby devicesKey: NSBonjourServicesType: ArrayValue: Item0: "_http-alt._tcp." (String)
3
If your end users prefer a language other than English, replace each default string assigned to Value with their language equivalents.
4
From Xcode, ensure your app continues to sync while it runs in the background, as well as when the end-user device is locked by enabling Bluetooth Background Modes:
From the left navigator area, click your project.
Click Signing & Capabilities.
Click + Capability and then, from the modal that appears, search and select Background Modes.
From TARGETS, select your app from the list.
From Background Modes, click to select the following:
If enabling the Data Protection entitlement, allow access after the end user has unlocked their device for the first time after a system restart by setting the entitlement to NSFileProtectionCompleteUntilFirstUserAuthentication.For more information, see the official Apple documentation for Data Protection Entitlement.
Once you’ve set up your environment, import the Ditto SDK in your codebase and obtain your access credentials.
Unless you have a specialized use case, such as a government app, you must connect to the internet at least once before you can sync offline with other peers.
1
From the top-most scope of your app’s codebase, add the following to set up authentication and start syncing offline.
2
Replace YOUR_APP_ID and YOUR_PLAYGROUND_TOKEN with your access credentials available from the portal.
ditto = Ditto( identity: DittoIdentity.onlinePlayground( appID: "REPLACE_ME_WITH_YOUR_APP_ID", token: "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN", enableDittoCloudSync: false, // This is required to be set to false to use the correct URLs customAuthURL: URL(string: "REPLACE_ME_WITH_YOUR_AUTH_URL") ))ditto.updateTransportConfig { transportConfig in // Set the Ditto Websocket URL transportConfig.connect.webSocketURLs.insert("wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL") // P2P sync is enabled by default across all transports. Disable those // if you are only using Ditto Cloud Sync. transportConfig.setPeerToPeer(enabled: false) }// Disable DQL strict mode so that collection definitions are not required in DQL queriestry await ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false")do { try ditto.startSync()} catch { print(error.localizedDescription)}